#import "SDTableViewHaedView.h"

@interface SDTableViewHaedView ()

//头像图片
@property (nonatomic,strong)UIImageView * im_headImage;
@property (nonatomic,strong)UILabel * lb_name;
//性别年龄图片与文本
@property (nonatomic,strong)UIImageView * im_gender;
@property (nonatomic,strong)UILabel * lb_gender;
//id图片与文本
@property (nonatomic,strong)UIImageView * im_idCard;
@property (nonatomic,strong)UILabel * lb_idCard;
//电话号码图像与文本
@property (nonatomic,strong)UIImageView * im_phoneNum;
@property (nonatomic,strong)UILabel * lb_phoneNum;
//地址图像与文本
@property (nonatomic,strong)UIImageView * im_adress;
@property (nonatomic,strong)UILabel * lb_adress;
//分割线
@property (nonatomic,weak)UIView * carve;
@end


@implementation SDTableViewHaedView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self showHeadViewSubView];
        

    }
    return self;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self showHeadViewSubView];
    }
    return self;
}

#pragma mark - 初始化子控件方法
- (void)showHeadViewSubView{
    //MARK: - 组头背景颜色
    self.backgroundColor = [UIColor whiteColor];
    //MARK: - 创建头像和名称
    self.im_headImage = [self newImageAndImageName:@"good_image_default"];
    self.lb_name = [self newLabel:@"李神医"];
    //MARK: - 创建性别
    self.im_gender = [self newImageAndImageName:@"0"];
    self.lb_gender = [self newLabel:@"女"];
    //MARK: - 创建ID
    self.im_idCard = [self newImageAndImageName:@"idCard"];
    self.lb_idCard = [self newLabel:@"23412984724"];
    //MARK: - 创建电话号码
    self.im_phoneNum = [self newImageAndImageName:@"phone"];
    self.lb_phoneNum = [self newLabel:@"133333333333"];
    //MARK: - 创建地址
    self.im_adress = [self newImageAndImageName:@"illness_rb_img_sel.png"];
    self.lb_adress = [self newLabel:@"上海市"];

    
}

#pragma mark - 子控件布局

- (void)layoutSubviews{
    [super layoutSubviews];
   //MARK: - 头像图片约束
   [self.im_headImage mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.leading.offset(20);
       make.height.width.mas_equalTo(100);
   }];
    //MARK: - name约束
    [self.lb_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.im_headImage.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.im_headImage.mas_centerX);
    }];
    //MARK: - 性别图片约束
    [self.im_gender mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_headImage.mas_top);
        make.leading.equalTo(self.im_headImage.mas_trailing).offset(10);
        make.width.height.offset(20);
    }];
    //MARK: - 性别label约束
    [self.lb_gender mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_gender.mas_top);
        make.leading.equalTo(self.im_gender.mas_trailing).offset(10);
    }];
    //MARK: - ID图片约束
    [self.im_idCard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_gender.mas_bottom).offset(10);
        make.leading.equalTo(self.im_headImage.mas_trailing).offset(10);
        make.width.height.offset(20);
    }];
    //MARK: - IDlabel约束
    [self.lb_idCard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_idCard.mas_top);
        make.leading.equalTo(self.im_idCard.mas_trailing).offset(10);
    }];
    //MARK: - 电话图片约束
    [self.im_phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_idCard.mas_bottom).offset(10);
        make.leading.equalTo(self.im_headImage.mas_trailing).offset(10);
        make.height.offset(20);
        make.width.offset(15);
    }];
    //MARK: - 电话label约束
    [self.lb_phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_phoneNum.mas_top);
        make.leading.equalTo(self.im_phoneNum.mas_trailing).offset(15);
    }];
    //MARK: - 地址图片约束
    [self.im_adress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_phoneNum.mas_bottom).offset(10)
        ;
        make.leading.equalTo(self.im_headImage.mas_trailing).offset(10);
        make.width.height.offset(20);
    }];
    //MARK: - 地址label约束
    [self.lb_adress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.im_adress.mas_top);
        make.leading.equalTo(self.im_idCard.mas_trailing).offset(10);
    }];

    [self showCarveView];
    
}

#pragma mark - 分割线
- (void)showCarveView{
    
    if (self.carve == nil) {
        
        UIView * carve = [[UIView alloc]initWithFrame:CGRectMake(10, self.bounds.size.height - 7, self.bounds.size.width - 20, 2)];
        carve.backgroundColor = [UIColor grayColor];
        [self addSubview:carve];
        self.carve = carve;
    }
}

#pragma mark - label创建的封装方法
- (UILabel *)newLabel:(NSString *)str{
    
    UILabel * tempLabel = [[UILabel alloc]init];
    
    tempLabel.text = str;
    
    [self addSubview:tempLabel];


    return tempLabel;
}

#pragma mark - image创建的封装方法
- (UIImageView *)newImageAndImageName:(NSString *)imageName{
    
    UIImageView * tempImge = [[UIImageView alloc]init];
    
    tempImge.image = [UIImage imageNamed:imageName];
    
    [self addSubview:tempImge];
    
    return tempImge;
}


@end
